﻿using AutoMapper;
using MediatR;
using T_Rbac_APi.Application.Command.Operator;
using T_Rbac_Demain;
using T_Rbac_Rep.Interface;

namespace T_Rbac_APi.Application.CommandHandler.OperatorHandler
{
    public class OperatorUpdateHandlerCommand : IRequestHandler<OperatorUpdateCommand, int>
    {
        private readonly IMapper mapper;
        private readonly IOperator ioperator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mapper"></param>
        /// <param name="ioperator"></param>
        public OperatorUpdateHandlerCommand(IMapper mapper, IOperator ioperator)
        {
            this.mapper = mapper;
            this.ioperator = ioperator;
        }

        public async Task<int> Handle(OperatorUpdateCommand request, CancellationToken cancellationToken)
        {
            request.UpdateDate = DateTime.Now;
            request.UpdateBy = "小红";
            var list = mapper.Map<Operator>(request);
            return await  ioperator.Update(list);
        }
    }
}
